#导入相关的包
import numpy as np
from sklearn.linear_model import LogisticRegression

#初始化训练数据集
x = np.array([[2,3],[3,4],[6,5],[4,4],[3,2],[4,7],[5,4],[4,3],[7,5],[3,3],[4,4],[5,2]])
y = np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])

#初始化测试数据集
x_test = np.array([[3,5],[2,4],[5,6],[3,6],[3,3],[4,5],[4,2],[5,5],[6,7],[5,3],[6,4],[6,6]])
y_test = np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])

#建立并训练模型
model = LogisticRegression()
model.fit(x,y.ravel())

#求解逻辑回归方程参数
print(f"w = {model.coef_}, b={model.intercept_}")

#模型预测准确率评估
r2 = model.score(x_test,y_test)
print(f"模型预测准确率评估： {r2}")
#预测辣度3，保质期7的辣椒酱是否会被顾客购买
y_pre = model.predict([[8,7]])
print(f"预测辣度3，保质期7的辣椒酱是否会被顾客购买：{y_pre}")
